package com.phonepn.mymall.goods.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author quifar
 */
@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {

    @SentinelResource(value = "test"

            , blockHandler = "exceptionHandler")
    @GetMapping
    public String test() {
        log.info(Thread.currentThread().getName() + "....");
        return "hello goods services";
    }

    // 限流与阻塞处理
    public String exceptionHandler(String str, BlockException ex) {
        log.error("blockHandler：" + str, ex);
        return "自定义异常返回";
    }

}
